package com.qf.service;

import com.qf.utils.ConnectionUtils;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

public class DocServiceImpl implements DocService {
    @Override
    public void addDoc(String index,String source) throws IOException {
        RestHighLevelClient highLevelClient = ConnectionUtils.getClient();
        IndexRequest indexRequest = new IndexRequest(index);
        indexRequest.source(source, XContentType.JSON);  //设置要添加的数据以及各式为json
        IndexResponse response = highLevelClient.index(indexRequest, RequestOptions.DEFAULT);
        System.err.println(response.toString());
    }
}
